<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <c:set var="path" value="${pageContext.request.contextPath}"></c:set>
    <link rel="shortcut icon" href="${path}/images/titleico.ico">
    <link rel="stylesheet" href="${path}/layui/css/layui.css">
    <link rel="stylesheet" href="${path}/layui/css/formSelects-v4.css">
    <script src="${path}/layui/layui.js"></script>
    <script src="${path}/js/jquery.js"></script>
</head>
<body>
<br>
<h1 style="text-align: center">我的资料</h1>
<hr class="layui-bg-blue">
<br>
<form class="layui-form" lay-filter="userFrom" id="userFrom" name="userFrom">
<div class="layui-form-item layui-col-md-offset3">
    <div class="layui-inline">
        <div class="layui-form" action="">
            <input type="hidden" name="id">
            <input type="hidden" name="password">
            <!--用户名-->
            <div class="layui-form-item">
                <label class="layui-form-label">用户名：</label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" style="width: 300px;"  autocomplete="off" placeholder="请输入用户名" class="layui-input">
                </div>
            </div>
            <!--账号-->
            <div class="layui-form-item">
                <label class="layui-form-label">账号：</label>
                <div class="layui-input-block">
                    <input type="text" name="account" autocomplete="off" placeholder="" disabled class="layui-input">
                </div>
            </div>
            <!--密码-->
            <div class="layui-form-item">
                <label class="layui-form-label">原密码：</label>
                <div class="layui-input-block">
                    <input type="password" name="olepassword" id="password" disabled autocomplete="off" placeholder="请输入密码" class="layui-input">
                </div>
            </div>
            <!--密码-->
            <div class="layui-form-item">
                <label class="layui-form-label">新密码：</label>
                <div class="layui-input-block">
                    <input type="password" name="newpassword" style="width: 250px;" id="xpassword" autocomplete="off" placeholder="请确认密码" class="layui-input"><a href="javascript:void(0)" style="float: right;margin-top: -30px;" id="qshowp"><img
                        src="${path}/images/showpwd.png" style="width: 45px;height: 30px;margin-top: -5px;" alt=""></a>
                </div>
            </div>
            <!--密码-->
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码：</label>
                <div class="layui-input-block">
                    <input type="password" name="qxpassword" id="qxpassword" autocomplete="off" placeholder="请确认密码" class="layui-input">
                </div>
            </div>
            <!--状态-->
            <div class="layui-form-item">
                <label class="layui-form-label">我的状态：</label>
                <div class="layui-input-block">
                    <input type="checkbox" id="state" name="state" lay-skin="switch" lay-text="冻结|可用" value="1">
                    <br><br><span style="color: red;font-size: 12px;text-align: right">注意！如果冻结以后此账号不可登录</span>
                </div>
            </div>
            <div style="width: 390px; margin: 0;">
                <button onclick="upuser()" type="button" class="layui-btn layui-btn-fluid" style="margin-left: 20px;">修&ensp;&ensp;&ensp;改</button>
            </div>
        </div>
    </div>
    </div>
</div>
</form>
<script>
    layui.use('form', function(){
        layui.form.val('userFrom',${sessionScope.admin});
        //获取旧密码赋值原密码框
        $(":input[name = 'olepassword']").val($(":input[name = 'password']").val());
    });
</script>
<script>
    window.onload=function(){
         var btn=document.getElementById("qshowp");
         var pass=document.getElementById("xpassword")
         btn.onmousedown=function(){
             pass.type="text"
         };
         btn.onmouseup=btn.onmouseout=function(){
             pass.type="password"
         }
     }
</script>
<script>
    layui.use("layer");
    function upuser() {
        var name = $("#name").val();
        var xpwd = $("#xpassword").val();
        var qxpwd = $("#qxpassword").val();
        if (name == null || name==""){
            layer.msg("<v style='color:red'>" + "用户名不能为空！" + "</v>", {time: 1200, icon: 5});
            return false;
        }else if (xpwd == null || xpwd == ""){
            layer.msg("<v style='color:red'>" + "新密码不能为空！" + "</v>", {time: 1200, icon: 5});
            return false;
        }else if(qxpwd == null || qxpwd == ""){
            layer.msg("<v style='color:red'>" + "确认新密码不能为空！" + "</v>", {time: 1200, icon: 5});
            return false;
        }else if(xpwd != qxpwd){
            layer.msg("<v style='color:red'>" + "输入的密码不一致！" + "</v>", {time: 1200, icon: 5});
            return false;
        };

        $(":input[name = 'password']").val($(":input[name = 'newpassword']").val());
        var params=$("#userFrom").serialize();
        $.post("${path}/Login/update",params,function (data) {
            layer.msg("修改成功!请重新登录",{time:700,anim:4},function () {
                window.location.href="${path}/Login/loginout";
                window.parent.location.href="${path}/Login/login";
            });
        });
    };
</script>
</body>
</html>